import request from '@/utils/axios/request'
import API from './constants'

/**
 * 获取正在热映的电影
 * @returns 电影条数
 */
export const getTags = () => {
  return request({
    url: API.TAGS_API,
    method: 'POST',
    params: {
      start: 0,
      count: 20,
    },
    data: {
      apikey: '0df993c66c0c636e29ecbb5344252a4a',
    },
  }).then((result) => {
    // console.log(result)
    return result
  }).catch(console.log)
}

/**
 * 查询电影信息
 * @param {number} id 电影id值
 * @returns 电影详情
 */
export const getDetail = (id) => {
  return request({
    url: API.DETAILS_API + '/' + id,
    method: 'POST',
    data: {
      apikey: '0df993c66c0c636e29ecbb5344252a4a',
    },
  }).then((result) => {
    // console.log(result)
    return result
  }).catch(console.log)
}

export const getTrailers = (id) => {
  return request({
    url: API.DETAILS_API + '/' + id + '/photos',
    method: 'POST',
    params: {
      apikey: '0df993c66c0c636e29ecbb5344252a4a',
    },
    data: {
      apikey: '0df993c66c0c636e29ecbb5344252a4a',
    },
  }).then((result) => {
    // console.log(result)
    return result
  }).catch(console.log)
}

/**
 * 获取短评
 * @param {number} id
 * @param {number} start
 * @param {number} count
 * @returns
 */
export const getComment = (id, start, count) => {
  return request({
    url: API.DETAILS_API + '/' + id + '/comments',
    method: 'POST',
    params: {
      start,
      count,
      apikey: '0df993c66c0c636e29ecbb5344252a4a',
    },
    data: {
      apikey: '0df993c66c0c636e29ecbb5344252a4a',
    },
  }).then((result) => {
    // console.log(result)
    return result
  }).catch(console.log)
}

/**
 * 获取每周热榜
 * @returns
 */
export const getWeekly = () => {
  return request({
    url: API.WEEKLY_API,
    method: 'POST',
    params: {
      apikey: '0df993c66c0c636e29ecbb5344252a4a',
    },
    data: {
      apikey: '0df993c66c0c636e29ecbb5344252a4a',
    },
  }).then((result) => {
    // console.log(result)
    return result
  }).catch(console.log)
}
/**
 * 获取TOP250
 * @returns
 */
export const getTop250 = (start, count) => {
  return request({
    url: API.TOP250_API,
    method: 'POST',
    params: {
      start,
      count,
    },
    data: {
      apikey: '0df993c66c0c636e29ecbb5344252a4a',
    },
  }).then((result) => {
    // console.log(result)
    return result
  }).catch(console.log)
}
